package com.devMode.BridgeMode;

/**
 * 桥接模式
 * 将抽象与实现分离开来，使其可以独立变化
 */
public class BridgeMode {
    public static void main(String[] args) {
        RemoteController remoteController1 = new ConcreateRemoteController(new RCA());
        remoteController1.on();
        remoteController1.off();
        remoteController1.tuneChannel();
        RemoteController remoteController2 = new ConcreateRemoteController(new sony());
        remoteController2.on();
        remoteController2.off();
        remoteController2.tuneChannel();
    }
}

abstract class TV{
    public abstract void on();

    public abstract void off();

    public abstract void tuneChannel();
}

class sony extends TV{

    @Override
    public void on() {
        System.out.println("sony on...");
    }

    @Override
    public void off() {
        System.out.println("sony off...");
    }

    @Override
    public void tuneChannel() {
        System.out.println("sony tuneChannel...");
    }
}

class RCA extends TV{

    @Override
    public void on() {
        System.out.println("RCA on...");
    }

    @Override
    public void off() {
        System.out.println("RCA off...");
    }

    @Override
    public void tuneChannel() {
        System.out.println("RCA tuneChannel...");
    }
}

abstract class RemoteController{
    protected TV tv;

    public RemoteController(TV tv){
        this.tv = tv;
    }

    abstract void on();

    abstract void off();

    abstract void tuneChannel();
}

class ConcreateRemoteController extends RemoteController{

    public ConcreateRemoteController(TV tv){
        super(tv);
    }

    @Override
    void on() {
        System.out.println("ConcreateRemoteController on...");
        tv.on();
    }

    @Override
    void off() {
        System.out.println("ConcreateRemoteController off...");
        tv.off();
    }

    @Override
    void tuneChannel() {
        System.out.println("ConcreateRemoteController tuneChannel...");
        tv.tuneChannel();
    }
}
